package com.zl.controller;

import com.select.pojo.Student;
import com.select.utils.CommonResult;
import com.zl.mapper.LoginMapper;
import com.zl.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Author ：ZhangLei
 * @Data ：2021/5/18 14:45
 * @Description ：
 */
@RestController
@RequestMapping("/student")
public class LoginController {

//    @Autowired
//    private LoginService loginService;

    @Autowired
    private LoginMapper loginMapper;

    public Map mapToke = new HashMap();

    /**
     * 登录
     *
     * @return
     */
    @PostMapping("/login")
    public CommonResult stuLogin (@RequestBody Student student) {
//        Student stu = loginService.stuLogin(student.getStuAccount(),student.getStuPassword());
        /**
         * 改写登录实现类，使用Lambda表达式
         */
        LoginService loginService = (s,t) -> loginMapper.stuLogin(s,t);
        Student stu = loginService.stuLogin(student.getStuAccount(),student.getStuPassword());
        UUID uuid = UUID.randomUUID();
        String toke = uuid.toString();
        mapToke.put(toke,toke);
        Map map = new HashMap(2);
        map.put("student",stu);
        map.put("toke",toke);
        if (stu == null){
            return CommonResult.ok(555,null,"错误");
        }
        return CommonResult.ok("登录成功",map);
    }

}
